<?php

namespace app\modules\order\controllers;

use Yii;
use yii\web\Controller;
use common\models\Tools;
use common\models\Order;

/**
 * Default controller for the `order` module
 */
class CreateController extends Controller
{
    public $enableCsrfValidation = false;
    /***
     * 创建订单
     */
    public function actionIndex(){
        
        if (Yii::$app->user->isGuest) {
            $output['success'] = 0;
            $output['msg'] = "未登录";
            $output['errorcode'] = 1001;
            Tools::outputjson($output);
        }
        $userid = Yii::$app->user->identity->id;
        $username = Yii::$app->user->identity->username;
        $invitor_id = Yii::$app->user->identity->invitor_id;
        
        $goods_info = $_POST['goods_info'];//参数内含有数组，不能用 Tools::GetSafeParam()
        
        
        
        $order_no = Order::createOrder($userid,$username,$invitor_id,$goods_info);
        
        $output['success'] = 1;
        $output['order_no'] = $order_no;
        Tools::outputjson($output);
    }
}
